package ascript.utilities
{
	//#########################
	// Header Includes
	//#########################
	import flash.geom.Point;
	import starling.display.Image;
	import starling.display.Sprite;
	import starling.textures.Texture;
	import flash.geom.Rectangle;
	
	//#########################
	// GraphicsTiled Class
	//#########################
	public class GraphicsTiled extends Sprite
	{
		
		//=========================
		// Constructors
		//=========================	
		
		//public function GraphicsTiled( tTexture:Texture, tIsVisible:Boolean = true, tLocation:PointSimple = null, tPivot:PointSimple = null, tRepeat:PointSimple = null, tScale:PointSimple = null ):void
		public function GraphicsTiled( tTexture:Texture, tIsVisible:Boolean, tLocation:PointSimple, tLocationLocal:PointSimple, tPivot:PointSimple, tRepeat:PointSimple, tScale:PointSimple ):void
		{		
			x = tLocation.x;
			y = tLocation.y;
			pivotX = tPivot.x;
			pivotY = tPivot.y;
			visible = tIsVisible;
			
			addGraphic( tTexture, tLocationLocal, tRepeat, tScale );
		}
		
		//=========================
		// Members
		//=========================
		public function addGraphic( tTexture:Texture, tLocationLocal:PointSimple, tRepeat:PointSimple, tScale:PointSimple ):void
		{
			var tempTexture:Texture = tTexture;
			var tempImage:Image = new Image( tempTexture );
			
			tempTexture.repeat = true;
			
			tempImage.x = tLocationLocal.x;
			tempImage.y = tLocationLocal.y;
			tempImage.setTexCoords( 1, new Point( tRepeat.x, 0 ) );
			tempImage.setTexCoords( 2, new Point( 0, tRepeat.y ) );
			tempImage.setTexCoords( 3, new Point( tRepeat.x, tRepeat.y ) );
			
			tempImage.width *= tRepeat.x;
			tempImage.height *= tRepeat.y;
			tempImage.scaleX /= tScale.x;
			tempImage.scaleY /= tScale.y;
			
			addChild( tempImage );
		}
		
		public function flattenGraphic( tIsFlattened:Boolean = true ):void
		{
			if ( tIsFlattened )
			{
				flatten();
			}
			else
			{
				unflatten();
			}
		}
	}
}